program example
use polymorphic_complextaylor
implicit none 
integer no,nv,i
type(double_complex) f,g
complex(dp) c,cc

no=4; nv= 2;  ! no: the order of the polynomial    nv: the number of variables
call init(no,nv)  ! initializes taylor series without maps

call alloc(f,g)      ! must be constructed after init

i=4

c=cmplx(5.d0,-1.4d0,kind=dp)
cc=cmplx(6.d0,1.6d0,kind=dp)  

f=(c.mono.'12') + (c.mono.'22') + (cc.mono.'13') + 3.d0
   ! Creates (5.d0 x_1x_2^2 - 1.4d0 i* x_1x_2^2) + (5.d0 x_1^2 x_2^2 - 1.4d0 i* x_1^2 x_2^2) 
   !                   + (6.d0 x_1x_2^3 + 1.6d0 i*  x_1x_2^3) + 3.d0
g=f.sub.i        !   Creates (5.d0 x_1^2 x_2^2 - 1.4d0 i* x_1^2 x_2^2) + (6.d0 x_1x_2^3 + 1.6d0 i*  x_1x_2^3) 

call print(f,6)
call print(g,6)

!   (Should return 3.d0 as a Complex Taylor!!!!!!!!!!!!!!!!!!!!!!!!!!!)
i=0
f=(c.mono.'12') + (c.mono.'22') + (cc.mono.'13') + 3.d0
   ! Creates (5.d0 x_1x_2^2 - 1.4d0 i* x_1x_2^2) + (5.d0 x_1^2 x_2^2 - 1.4d0 i* x_1^2 x_2^2) 
   !                   + (6.d0 x_1x_2^3 + 1.6d0 i*  x_1x_2^3) + 3.d0
g=f.sub.i        !   Creates 3.d0 as a Complex Taylor   <-----------------  comment changed

call print(f,6)
call print(g,6)




!   (Should return f)        <--------------------------- Error message when executed!
!i=0
!f=cmplx(5.d0,-1.4d0,kind=dp)
!g=f.sub.i        

!call print(f,6)
!call print(g,6)

!  (Should return zero)      <-------------------------- Error message when executed!
!i=2
!f=cmplx(5.d0,-1.4d0,kind=dp)
!g=f.sub.i        

!call print(f,6)
!



call kill(f,g)      ! must be destroyed
end program example